﻿using System.Reflection;
using System.Web.Mvc;

namespace SS.AspNet.Utilities
{
    /// <summary>
    /// The class is used to support overload actions in controllers
    /// </summary>
    public class RequireRequestValueAttribute : ActionMethodSelectorAttribute
    {
        public RequireRequestValueAttribute(string[] valueNames)
        {
            ValueNames = valueNames;
        }

        public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
        {
            var contains = false;
            foreach (var value in ValueNames)
            {
                contains = controllerContext.HttpContext.Request[value] != null;
                if (!contains)
                {
                    break;   
                }
            }
            return contains;
        }

        public string[] ValueNames { get; private set; }
    }
}